﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using YGWebMobileApi.Data;
using OneMile.BLL;
using OneMile.Common;

namespace YGWebMobileApi.APIs
{
    [MobileAPI(Code = "MC0333", Name = "用户删除地址")]
    public class UDelAddress : BaseAPI, IProcessMessage
    {
        private BLLUUserAddress bllAddr;
        public BLLUUserAddress BllAddr
        {
            get
            {
                if (bllAddr == null)
                    bllAddr = BLLFactory.getInstance().CreateUUserAddressBLL();
                return bllAddr;
            }
        }

        #region IProcessMessage 成员
        public MobileRspMsg ProcessMessage(MobileReqMsg reqMsg)
        {
            try
            {
                MobileRspMsg rspMsg = new MobileRspMsg(reqMsg);
                // 获取参数字段（具体请参见文档）
                string UserAddressId = reqMsg.Body.GetFieldValue("UserAddressId");

                if (string.IsNullOrEmpty(UserAddressId))
                {
                    rspMsg.Head.RspCode = MessageCode.Paramter_Empty.Code;
                    rspMsg.Head.RspMsg = MessageCode.Paramter_Empty.Msg;
                    return rspMsg;
                }

                if (BllAddr.DelUserAddress(UserAddressId))
                {
                    rspMsg.Head.RspCode = MessageCode.Success.Code;
                    rspMsg.Head.RspMsg = MessageCode.Success.Msg;

                    return rspMsg;
                }
                else
                {
                    rspMsg.Head.RspCode = MessageCode.Server_Error.Code;
                    rspMsg.Head.RspMsg = MessageCode.Server_Error.Msg;

                    return rspMsg;
                }
            }  
            catch (Exception e)
            {
                ErrorLogWriter.Write("UDelAddress-" + e);
                throw e;
            }

        }
        #endregion
    }
}